package com.yanqu.road.dao.impl.activity.xiayue;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.xiayue.config.XiaYueNpcConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class XiaYueNpcConfigDaoImpl extends TempDao {

    private static String getXiaYueNpcConfigSql = "select * from `t_s_activity_xiayue_npc` where `activityId`=?";

    public List<XiaYueNpcConfig> getXiaYueNpcConfigList(int activityId) {
        List<XiaYueNpcConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getXiaYueNpcConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                XiaYueNpcConfig xiaYueNpcConfig = new XiaYueNpcConfig();
                xiaYueNpcConfig.setActivityId(rs.getInt("activityId"));
                xiaYueNpcConfig.setNpcId(rs.getInt("npcId"));
                xiaYueNpcConfig.setName(rs.getString("name"));
                xiaYueNpcConfig.setDesc(rs.getString("desc"));
                list.add(xiaYueNpcConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
